char *strcpy(char *dst, const char *src)
{
	char *dst_preserve = dst;
	do
	  {
		*dst++ = *src;
	  }
	while (*src++ != '\0');

	return dst_preserve;
}


char *strcat(char *dst, const char *src)
{
	char *dst_preserve = dst;
	while (*dst++ != '\0');
	--dst;
	do {
		*dst++ = *src;
	} while (*src++ != '\0');

	return dst_preserve;
}


int strcmp(const char *s1, const char *s2)
{
	while (*s1 == *s2 && *s1 != '\0') {
		++s1, ++s2;
	}
	return *s1 - *s2;
}


const char *strchr(const char *s, char c)
{
	while (*s != '\0' && *s != c)
		++s;
	return s;
}


const char *strrchr(const char *s, char c)
{
	unsigned int diff=0;
	while (*(s + diff) != '\0')
		++diff;
	do {
		if (*(s + diff) == c)
			return s + diff;
	} while (diff--  > 0);

	return (char*) 0;
}


const char *strstr(const char *s1, const char *s2)
{
	unsigned int i=0, j=0;
	while (*(s1+i) != '\0') {
		if (*(s1+i) == *s2) {
			while (*(s2+j) != '\0' && *(s1+i+j) == *(s2+j))
				++j;

			if (*(s2+j) == '\0')
				return s1 + i;
			else {
				j = 0;
				++i;
			}
		} else
			++i;
	}
	return (char*) 0;
}

int strspn(const char *s1, const char *s2)
{
	int ret = 0; /* result */
	unsigned int diff = 0;
	while (*s1 != '\0') { /* look thru the whole string */
		while (*(s2 + diff) != '\0') /* look thru the whole string */
			if (*(s2 + diff) == *s1) { /* if we found a match */
				++ret;
				break;
			} else {
				++diff;
			}
		if (*(s2 + diff) == '\0')
			return ret; /* we went all the way thru 's2' => no matching chars => job is done */
		diff = 0;
		++s1;
	}
	return ret;
}


int strcspn(const char *s1, const char *s2)
{
	int ret = 0;
	unsigned int diff = 0;
	while (*s1 != '\0') { /* look thru the whole string */
		while (*(s2 + diff) != '\0') {
			if (*(s2 + diff) != *s1)
				++diff;
			else
				break; /* return to parent loop */
		}

		if (*(s2 + diff) == '\0') { /* 's2' was scanned to the end => no mathing chars => move on */
			++ret;
			diff = 0; /* without this we have an inefficient analogue of strlen :-( */
			++s1;
		} else /* 's2' was NOT scanned to the the end => 's1' has a char from 's2' => stop */
			break; /* return from func */
	}
	return ret;
}


char *invert(char *s)
{
	char *s_pr = s;
	while (*s != '\0') {
		if (*s >= 'a' && *s <= 'z')
			*s = 'Z' - (*s - 'a');
		else if (*s >= 'A' && *s <= 'Z')
			*s = 'z' - (*s - 'A');

		++s;
	}
	return s_pr;
}
